package com.example.mall.web.controller;

import com.example.mall.domain.PayFlow;
import com.example.mall.dto.PayFlowDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.PayFlowQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IPayFlowService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/payFlow")
public class PayFlowController {

    @Autowired
    public IPayFlowService payFlowService;

    /**
     * 分页查询支付流水表信息
     * @param payFlowQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询支付流水表信息",notes = "分页查询支付流水表信息",httpMethod = "GET")
    public JSONResult queryPage(PayFlowQuery payFlowQuery){
        PageDTO<PayFlowDto> payFlowDtoPageDTO = payFlowService.queryPage(payFlowQuery);
        return JSONResult.success("查询成功",payFlowDtoPageDTO);
    }

    /**
     * 根据id查询支付流水表信息
     * @param id
     * @return
     */
    @GetMapping("query/{id}")
    @ApiOperation(value = "根据id查询支付流水表信息",notes = "根据id查询支付流水表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.PAY_FLOW_NOT_ID);
        }
        PayFlow payFlow = payFlowService.getById(id);
        return JSONResult.success("查询成功",payFlow);
    }

    /**
     * 根据id查询支付流水表信息
     * @param id
     * @return
     */
    @GetMapping("queryPayFlowById/{id}")
    @ApiOperation(value = "根据id查询支付流水表信息",notes = "根据id查询支付流水表信息",httpMethod = "GET")
    public JSONResult queryPayFlowById(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.PAY_FLOW_NOT_ID);
        }
        PayFlow payFlow = payFlowService.queryPayFlowById(id);
        return JSONResult.success("查询成功",payFlow);
    }

    /**
     * 查询全部支付流水表信息
     * @param
     * @return
     */
    @GetMapping("queryPayFlowList")
    @ApiOperation(value = "查询全部支付流水表信息",notes = "查询全部支付流水表信息",httpMethod = "GET")
    public JSONResult queryPayFlowList(){
        List<PayFlow> logins = payFlowService.queryPayFlowList();
        return JSONResult.success("查询成功",logins);
    }

    /**
     * 新增支付流水表
     * @param payFlowDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增支付流水表",notes = "新增支付流水表",httpMethod = "POST")
    public JSONResult insert(@RequestBody PayFlowDto payFlowDto){
        payFlowService.insert(payFlowDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改支付流水表信息
     * @param payFlowDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改支付流水表信息",notes = "修改支付流水表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody PayFlowDto payFlowDto){
        payFlowService.update(payFlowDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除支付流水表信息
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    @ApiOperation(value = "删除支付流水表信息",notes = "删除支付流水表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("activitiesProductId") Long id) {
        payFlowService.delete(id);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除支付流水表信息
     * @param ids
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除支付流水表信息",notes = "批量删除支付流水表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> ids) {
        payFlowService.deleteBatch(ids);
        return JSONResult.success("批量删除成功");
    }
}
